import pulpcore.Input;
import pulpcore.Stage;
import pulpcore.animation.Easing;
import pulpcore.animation.Timeline;
import pulpcore.animation.event.TimelineEvent;
import pulpcore.image.Colors;
import pulpcore.image.CoreFont;
import pulpcore.scene.Scene2D;
import pulpcore.sprite.FilledSprite;
import pulpcore.sprite.ImageSprite;
import pulpcore.sprite.Label;
import pulpcore.sprite.Sprite;

/**
 * Created by will
 * Date: May 24, 2008 11:32:40 PM
 */
public class IntroScene extends Scene2D {
    public static final int FADEIN = 1000;
    public static final int FADEOUT_TIME = 500;
    private Timeline t;
    private Timeline t2;
    private Sprite superJordanBros;
    private Label presentedBy;

    public void load() {
        Sprite background = new FilledSprite(0,0,Stage.getWidth(),Stage.getHeight(), Colors.BLACK);
        add(background);

        presentedBy = new Label("Presented by", Stage.getWidth()/2,Stage.getHeight()/3);
        presentedBy.setFont(CoreFont.getSystemFont().tint(Colors.WHITE));
        presentedBy.setAnchor(Sprite.CENTER);
        add(presentedBy);
        superJordanBros = new ImageSprite("jordanbros.png", Stage.getWidth()/2,Stage.getHeight()/2);
        getMainLayer().add(superJordanBros);
        double v = superJordanBros.width.get();
        double v1 = superJordanBros.height.get();
        double scale = 1.5;
        superJordanBros.setAnchor(Sprite.CENTER);
        t = new Timeline();
        t.scaleTo(superJordanBros,v*scale,v1*scale,4000);
        t.animate(superJordanBros.alpha,0,255,FADEIN, Easing.REGULAR_IN_OUT);
        t.animate(presentedBy.alpha,0,255,FADEIN, Easing.REGULAR_IN_OUT);
        addTimeline(t);
        t2 = new Timeline(3000);
//        t2.scale(superJordanBros,v*scale,v1*scale,v,v1,2000);
        t2.animateTo(superJordanBros.alpha,0,1000);
        t2.animateTo(presentedBy.alpha,0,1000);
        t2.addEvent(new TimelineEvent(1000) { public void run() {
                Stage.setScene(new MainMenuScene());
            }});
        addTimeline(t2);
    }

    boolean closing = false;
    public void update(int elapsedTime) {
        super.update(elapsedTime);
        if(Input.isMousePressed() && !closing) {
            closing=true;
            System.out.println("setting");
            removeTimeline(t2,false);
            t2 = new Timeline();
            t2.animateTo(superJordanBros.alpha,0,FADEOUT_TIME);
            t2.animateTo(presentedBy.alpha,0,FADEOUT_TIME);
            t2.addEvent(new TimelineEvent(FADEOUT_TIME) {
                public void run() {
                    removeTimeline(t, false);
                    Stage.setScene(new MainMenuScene());
                }
            });
            addTimeline(t2);
        }
    }
}
